Python Testing by Arbuckle Daniel
Author:Arbuckle, Daniel [Daniel Arbuckle]
Language: eng
Format: epub
Publisher: Packt Publishing
Time for action – creating a module fixture
We'll build a test module with a module-level fixture. In the fixture, we'll replace the datetime.date.today function, which normally returns an object representing the current date. We want it to return a specific value, so that our tests can know what to expect.
Create a directory called tests. We'll use this directory in this Time for action, as well as in the next one.
Within the tests directory, create a file called module_fixture_tests.py containing the following code:from unittest import TestCase from mocker import Mocker from datetime import date mocker = Mocker() def setup(): fake_date = mocker.replace(date) fake_date.today() mocker.result(date(year = 2009, month = 6, day = 12)) mocker.count(1, None) mocker.replay() def teardown(): mocker.restore() mocker.verify() class first_tests(TestCase): def test_year(self): self.assertEqual(date.today().year, 2009) def test_month(self): self.assertEqual(date.today().month, 6) def test_day(self): self.assertEqual(date.today().day, 12) class second_tests(TestCase): def test_isoformat(self): self.assertEqual(date.today().isoformat(), '2009-06-12')
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12571)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8298)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7076)
Microservices with Go by Alexander Shuiskov(6843)
Practical Design Patterns for Java Developers by Miroslav Wengner(6764)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6703)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6414)
Angular Projects - Third Edition by Aristeidis Bampakos(6108)
The Art of Crafting User Stories by The Art of Crafting User Stories(5638)
NetSuite for Consultants - Second Edition by Peter Ries(5570)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5375)
Kotlin in Action by Dmitry Jemerov(5063)
